﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using Gallio.Framework;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using System.Configuration;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;

namespace DotNetNuke.Tests.UI.WatiN.BuildVerification
{
    [TestFixture]
    [DependsOn(typeof(InstallTests))]
    [DependsOn(typeof(UpgradeTests))]
    public class TemplateTests : BVTBase
    {
        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {
            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {
            TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        [CsvData(ResourcePath = "TestData.InstallList.csv", HasHeader = true)]
        public void Verify_Sponsor_Links_In_Template(string version, string type)
        {
            if (type.Equals("UpgradeOnly"))
            {
                Gallio.Framework.TestLog.WriteLine("This test has not been run on an installation site.");
                Assert.IsTrue(true);
            }
            else
            {
                //Arrange
                string capturePath = CapturePath + @"\TemplateTests\VerifySponsorsLinksInTemplate\";
                WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
                if (!Directory.Exists(capturePath))
                {
                    Directory.CreateDirectory(capturePath);
                }
                WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
                TemplateHomePage template = new TemplateHomePage(homePage);

                try
                {
                    //Act & Assert
                    //ASP.Net Link
                    System.Threading.Thread.Sleep(7000);
                    watinAssert.AssertIsTrue(template.MsAspNetImage.Exists, "MissingASPNETLink.jpg");
                    template.MsAspNetImage.ClickNoWait();
                    System.Threading.Thread.Sleep(5000);
                    IE popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("http://www.asp.net")));
                    watinAssert.AssertIsTrue(popUpWindow.Title.Contains("The Official Microsoft ASP.NET Site"), "ASPNetPopUpWindowError.jpg", popUpWindow);
                    popUpWindow.Close();

                    //MaximumASP Link
                    //watinAssert.AssertIsTrue(template.MaximumASPImage.Exists, "MissingMaximumASPLink.jpg");
                    //template.MaximumASPImage.ClickNoWait();
                    //System.Threading.Thread.Sleep(5000);
                    //popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("http://www.maximumasp.com")));
                    //watinAssert.AssertIsTrue(popUpWindow.Title.Contains("MaximumASP"), "MaximumASPPopUpWindowError.jpg", popUpWindow);
                    //popUpWindow.Close();
                    
                    //CBeyond Link
                    watinAssert.AssertIsTrue(template.CBeyondImage.Exists, "MissingCBeyondLink.jpg");
                    template.CBeyondImage.ClickNoWait();
                    System.Threading.Thread.Sleep(5000);
                    popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("http://www.maximumasp.com")));
                    watinAssert.AssertIsTrue(popUpWindow.Title.Contains("MaximumASP"), "CBeyondPopUpWindowError.jpg", popUpWindow);
                    popUpWindow.Close();

                    //Telerik Link
                    watinAssert.AssertIsTrue(template.TelerikSponsorImage.Exists, "MissingTelerikLink.jpg");
                    template.TelerikSponsorImage.ClickNoWait();
                    System.Threading.Thread.Sleep(5000);
                    popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("http://www.telerik.com")));
                    watinAssert.AssertIsTrue(popUpWindow.Title.Contains("RadControls for ASP.NET AJAX in DNN | Telerik"), "TelerikPopUpWindowError.jpg", popUpWindow);
                    popUpWindow.Close();

                    //Exact Target Link
                    watinAssert.AssertIsTrue(template.ExactTargetImage.Exists, "MissingExactTargetLink.jpg");
                    template.ExactTargetImage.ClickNoWait();
                    System.Threading.Thread.Sleep(5000);
                    popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("http://www.exacttarget.com")));
                    watinAssert.AssertIsTrue(popUpWindow.Title.Contains("ExactTarget"), "ExactTargetPopUpWindowError.jpg", popUpWindow);
                    popUpWindow.Close();

                    //Windows Live Link
                    watinAssert.AssertIsTrue(template.WindowsLiveImage.Exists, "MissingWindowsLiveLink.jpg");
                    template.WindowsLiveImage.ClickNoWait();
                    System.Threading.Thread.Sleep(5000);
                    popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("http://msdn.microsoft.com/en-us/windowslive/default.aspx")));
                    watinAssert.AssertIsTrue(popUpWindow.Title.Contains("Windows Live Developer Center Home"), "WindowsLivePopUpWindowError.jpg", popUpWindow);
                    popUpWindow.Close();

                    //RedGate Link
                    watinAssert.AssertIsTrue(template.RedGateImage.Exists, "MissingRedGateLink.jpg");
                    template.RedGateImage.ClickNoWait();
                    System.Threading.Thread.Sleep(5000);
                    popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("http://www.red-gate.com")));
                    watinAssert.AssertIsTrue(popUpWindow.Title.Contains("Red Gate Software"), "RedGatePopUpWindowError.jpg", popUpWindow);
                    popUpWindow.Close();

                    //Applied Innovations Link
                    watinAssert.AssertIsTrue(template.AppliedInnovationsImage.Exists, "MissingAppliedInnovationLink.jpg");
                    template.AppliedInnovationsImage.ClickNoWait();
                    System.Threading.Thread.Sleep(5000);
                    popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("http://www.appliedi.net/windows-hosting/application/DotNetNuke/")));
                    watinAssert.AssertIsTrue(popUpWindow.Title.Contains("Top Ranked DotNetNuke Hosting "), "AppliedInnovationsPopUpWindowError.jpg", popUpWindow);
                    popUpWindow.Close();

                    //Arrow Consulting and Design Link
                    watinAssert.AssertIsTrue(template.ArrowConsultingDesignImage.Exists, "MissingAppliedInnovationLink.jpg");
                    template.ArrowConsultingDesignImage.ClickNoWait();
                    System.Threading.Thread.Sleep(5000);
                    popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("http://www.arrowdesigns.com/")));
                    watinAssert.AssertIsTrue(popUpWindow.Title.Contains("Arrow Consulting & Design"), "ArrowConsultingPopUpWindowError.jpg", popUpWindow);
                    popUpWindow.Close();
                }
                catch (Exception e)
                {
                    if (!e.ToString().Contains("AssertionFailureException"))
                    {
                        ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                        Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                    }
                    else
                    {
                        throw e;
                    }
                }

            }
        }



        #endregion
    }
}

